package com.dianping.cat.home.server.transform;

import com.dianping.cat.home.server.IEntity;
import com.dianping.cat.home.server.IVisitor;
import com.dianping.cat.home.server.entity.Group;
import com.dianping.cat.home.server.entity.Item;
import com.dianping.cat.home.server.entity.Segment;
import com.dianping.cat.home.server.entity.ServerMetricConfig;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  14 */   private Stack<Object> m_objs = new Stack();

  private ServerMetricConfig m_serverMetricConfig;


  public DefaultMerger() {}

  public DefaultMerger(ServerMetricConfig serverMetricConfig) {
/*  22 */     this.m_serverMetricConfig = serverMetricConfig;
/*  23 */     this.m_objs.push(serverMetricConfig);
  }


/*  27 */   public ServerMetricConfig getServerMetricConfig() { return this.m_serverMetricConfig; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  35 */     this.m_objs.push(to);
    from.accept(this);
/*  37 */     this.m_objs.pop();
  }


/*  41 */   protected void mergeGroup(Group to, Group from) { to.mergeAttributes(from); }



/*  45 */   protected void mergeItem(Item to, Item from) { to.mergeAttributes(from); }



/*  49 */   protected void mergeSegment(Segment to, Segment from) { to.mergeAttributes(from); }



/*  53 */   protected void mergeServerMetricConfig(ServerMetricConfig to, ServerMetricConfig from) { to.mergeAttributes(from); }



  public void visitGroup(Group from) {
/*  58 */     Group to = (Group)this.m_objs.peek();

/*  60 */     mergeGroup(to, from);
/*  61 */     visitGroupChildren(to, from);
  }

  protected void visitGroupChildren(Group to, Group from) {
/*  65 */     for (Item source : from.getItems().values()) {
/*  66 */       Item target = to.findItem(source.getId());

/*  68 */       if (target == null) {
/*  69 */         target = new Item(source.getId());
/*  70 */         to.addItem(target);
      }

/*  73 */       this.m_objs.push(target);
/*  74 */       source.accept(this);
/*  75 */       this.m_objs.pop();
    }
  }


  public void visitItem(Item from) {
/*  81 */     Item to = (Item)this.m_objs.peek();

/*  83 */     mergeItem(to, from);
/*  84 */     visitItemChildren(to, from);
  }

  protected void visitItemChildren(Item to, Item from) {
/*  88 */     for (Segment source : from.getSegments().values()) {
/*  89 */       Segment target = to.findSegment(source.getId());

/*  91 */       if (target == null) {
/*  92 */         target = new Segment(source.getId());
/*  93 */         to.addSegment(target);
      }

/*  96 */       this.m_objs.push(target);
/*  97 */       source.accept(this);
/*  98 */       this.m_objs.pop();
    }
  }


  public void visitSegment(Segment from) {
/* 104 */     Segment to = (Segment)this.m_objs.peek();

/* 106 */     mergeSegment(to, from);
/* 107 */     visitSegmentChildren(to, from);
  }


  protected void visitSegmentChildren(Segment to, Segment from) {}


  public void visitServerMetricConfig(ServerMetricConfig from) {
/* 115 */     ServerMetricConfig to = (ServerMetricConfig)this.m_objs.peek();

/* 117 */     mergeServerMetricConfig(to, from);
/* 118 */     visitServerMetricConfigChildren(to, from);
  }

  protected void visitServerMetricConfigChildren(ServerMetricConfig to, ServerMetricConfig from) {
/* 122 */     for (Group source : from.getGroups().values()) {
/* 123 */       Group target = to.findGroup(source.getId());

/* 125 */       if (target == null) {
/* 126 */         target = new Group(source.getId());
/* 127 */         to.addGroup(target);
      }

/* 130 */       this.m_objs.push(target);
/* 131 */       source.accept(this);
/* 132 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/server/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */